--
-- Author: shunguo.chen
-- Date: 2019-05-17 17:04:23
--

local GameDB = import(".GameDB")

function GameDB:getLegendStarConf(id)
    return self:getCachedValue("legendstarskill", id)
end

-- id legend表内legendSkills技能组id，需要特意通过legendkill转化成class_skill表组id
-- 服务器需要的逻辑
function GameDB:getLegendSkillTeam(id)
    local conf = self:getCachedValue("legendskill", id)
    if conf then
        return tonumber(conf.skillTeamID or 0)
    end
    return 0
end

function GameDB:getLegendStarMapConf(id)
    return self:getCachedValue("legendstarmap", id)
end

function GameDB:getLegendPropShowConf(propId)
    local conf = self:getCachedValue("legendstarmappropshow", propId)
    return conf
end

GameDB._legendShowPropsDict = {}
-- 返回传奇星图属性显示顺序表 {{id,name,value,format}, ...}
function GameDB:getLegendStarMapPropShow(classId)
    local showProps = self._legendShowPropsDict[classId]
    if not showProps then
        local confs = self:getCachedValues("legendstarmappropshow",
            nil,
            function(a, b)
                return tonumber(a.order) < tonumber(b.order)
            end)

        showProps = {}
        for i,conf in ipairs(confs) do
            if string.isContain(conf.roleSuit, classId) then
                local attr = {tonumber(conf.ID), conf.propName, 0, tonumber(conf.format)}
                showProps[#showProps + 1] = attr
            end
        end
        self._legendShowPropsDict[classId] = showProps
    end
    return showProps
end

function GameDB:getLegendPropFormat(classId, propId)
    local showProps = self:getLegendStarMapPropShow(classId)
    for i,prop in ipairs(showProps) do
        if prop[1] == propId then
            return prop[2], prop[4]
        end
    end
end

function GameDB:getLegendFashionConfs(legendId)
    return self:getCachedValues("legendfashion",
        function(v)
            return tonumber(v.legendID) == tonumber(legendId)
        end, 
        function(a, b)
            return tonumber(a.fashionNum) < tonumber(b.fashionNum)
        end)
end

function GameDB:getLegendLvConf(lv)
    return self:getCachedValue("legendlv", lv)
end

function GameDB:getLegendConfs(classId)
    return self:getCachedValues("legend",
        function(v)
            return v.open == "1" and tonumber(v.class) == tonumber(classId)
        end, 
        function(a, b)
            return tonumber(a.ID) < tonumber(b.ID)
        end)
end

return GameDB